using System;
using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class ItemWeaponEquipment : ItemEquipment
{
	private CharacterSystem character;

	public GameObject MuzzleFX;

	public GameObject ProjectileFX;

	private AudioSource audioSource;

	public AudioClip SoundFire;

	public AudioClip[] DamageSound;

	private void Start()
	{
		audioSource = GetComponent<AudioSource>();
		if ((bool)base.transform.root)
		{
			character = base.transform.root.GetComponent<CharacterSystem>();
		}
		else
		{
			character = base.transform.GetComponent<CharacterSystem>();
		}
		if ((bool)character)
		{
			character.DamageSound = DamageSound;
		}
	}

	public override void Action(Vector3 direction, byte num, byte spread, byte seed)
	{
		if (audioSource != null && SoundFire != null && audioSource.enabled && audioSource.isActiveAndEnabled)
		{
			audioSource.PlayOneShot(SoundFire);
		}
		if ((bool)MuzzleFX)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate(MuzzleFX, base.transform.position, base.transform.rotation);
			gameObject.transform.parent = base.transform;
			UnityEngine.Object.Destroy(gameObject, 2f);
		}
		if ((bool)ProjectileFX && num <= 1)
		{
			System.Random random = new System.Random(seed);
			for (int i = 0; i < num; i++)
			{
				Vector3 forward = direction + new Vector3((float)random.Next(-spread, spread) * 0.001f, (float)random.Next(-spread, spread) * 0.001f, (float)random.Next(-spread, spread) * 0.001f);
				GameObject gameObject2 = UnityEngine.Object.Instantiate(ProjectileFX, base.transform.position, base.transform.rotation);
				gameObject2.transform.forward = forward;
			}
		}
		base.Action(direction, num, spread, seed);
	}
}
